﻿' ******************************************************************************
' ** 
' **  Yahoo! Managed
' **  Written by Marius Häusler 2011
' **  It would be pleasant, if you contact me when you are using this code.
' **  Contact: YahooFinanceManaged@gmail.com
' **  Project Home: http://code.google.com/p/yahoo-finance-managed/
' **  
' ******************************************************************************
' **  
' **  Copyright 2011 Marius Häusler
' **  
' **  Licensed under the Apache License, Version 2.0 (the "License");
' **  you may not use this file except in compliance with the License.
' **  You may obtain a copy of the License at
' **  
' **    http://www.apache.org/licenses/LICENSE-2.0
' **  
' **  Unless required by applicable law or agreed to in writing, software
' **  distributed under the License is distributed on an "AS IS" BASIS,
' **  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' **  See the License for the specific language governing permissions and
' **  limitations under the License.
' ** 
' ******************************************************************************


Namespace YahooManaged.Finance

    ''' <summary>
    ''' Stores informations about one historic trading period (day, week or month).
    ''' </summary>
    ''' <remarks></remarks>
    Public Class HistQuoteData
        Private mValues(5) As Double

        ''' <summary>
        ''' The startdate of the period.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property TradingDate() As Date
        ''' <summary>
        ''' The traded volume.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Volume() As Long
        ''' <summary>
        ''' The first value in trading period.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Open() As Double
            Get
                Return mValues(0)
            End Get
            Set(ByVal value As Double)
                mValues(0) = value
            End Set
        End Property
        ''' <summary>
        ''' The highest value in trading period.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property High() As Double
            Get
                Return mValues(1)
            End Get
            Set(ByVal value As Double)
                mValues(1) = value
            End Set
        End Property
        ''' <summary>
        ''' The lowest value in trading period.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Low() As Double
            Get
                Return mValues(2)
            End Get
            Set(ByVal value As Double)
                mValues(2) = value
            End Set
        End Property
        ''' <summary>
        ''' The last value in trading period.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Close() As Double
            Get
                Return mValues(3)
            End Get
            Set(ByVal value As Double)
                mValues(3) = value
            End Set
        End Property
        ''' <summary>
        ''' The last value in trading period in relation to share splits.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CloseAdjusted() As Double
            Get
                Return mValues(4)
            End Get
            Set(ByVal value As Double)
                mValues(4) = value
            End Set
        End Property
        ''' <summary>
        ''' The close value of the previous HistQuoteData in chain.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property PreviousClose() As Double
            Get
                Return mValues(5)
            End Get
            Set(ByVal value As Double)
                mValues(5) = value
            End Set
        End Property

    End Class




    ''' <summary>
    ''' HistQuotesDataChain is a collection class for HistQuoteData. Implements IID. Inherits Collection(Of HistQuoteData).
    ''' </summary>
    ''' <remarks></remarks>
    Public Class HistQuotesDataChain
        Inherits Collections.ObjectModel.Collection(Of HistQuoteData)
        Implements ISettableID

        Private mID As String = String.Empty

        ''' <summary>
        ''' The ID of the historic quotes owning stock, index, etc.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property ID() As String Implements IID.ID
            Get
                Return mID
            End Get
        End Property
        Public Sub SetID(ByVal id As String) Implements ISettableID.SetID
            mID = id
        End Sub

        Public Sub New()
            MyBase.New()
        End Sub
        Public Sub New(ByVal id As String)
            MyBase.New()
            mID = id
        End Sub
        Public Sub New(ByVal items As IEnumerable(Of HistQuoteData))
            MyBase.New()
            For Each i In items
                MyBase.Add(i)
            Next
            If MyBase.Count > 0 Then
                For i As Integer = 0 To MyBase.Count - 1
                    If i > 0 Then
                        MyBase.Item(i).PreviousClose = MyBase.Item(i - 1).Close
                    End If
                Next
            End If
        End Sub
        Public Sub New(ByVal id As String, ByVal items As IEnumerable(Of HistQuoteData))
            Me.New(items)
            mID = id
        End Sub

    End Class
End Namespace